import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
// 首页
// import index from '@/components/dashboard/index.vue';
import index from '@/views/index.vue';
//
import ReportSearch from '@/views/report/ReportSearch.vue';
import ReportGeneration from '@/views/report/ReportGeneration.vue';
import ReportGenerationCOPD from "@/views/reportCOPD/ReportGenerationCOPD.vue";
import ReportSearchCOPD from "@/views/reportCOPD/ReportSearchCOPD.vue";
// 交易订单
import Order from '@/views/pay/Order.vue';
// 用户管理
import user from '@/views/user/User.vue';
// 医生管理
import doctor from '@/views/user/Doctor.vue';
// 角色管理
import Role from '@/views/system/Role.vue';
// 用户信息
import UserInfo from '@/views/user/UserInfo.vue'
// 设备绑定
import Binding from '@/views/equipment/Binding.vue';
// 设备解绑
import Unbind from '@/views/equipment/Unbind.vue';
// 审核绑定
import AuditBinding from '@/views/equipment/AuditBinding.vue';
//设备借出与归还
import borrowAndReturn from '@/views/equipment/borrowAndReturn.vue';
// 权限管理
import Permission from '@/views/system/Permission.vue';
import SleepModelSetup from '@/views/system/SleepModelSetup.vue';
// 支付配置
import Config from '@/views/pay/Config.vue';
// 图表界面
import statistics from '@/views/charts/statistics.vue';
import Main from '@/views/system/Main.vue'
import login from '@/views/login/login.vue'
// 模型设置
import sound from '@/views/setting/sound.vue'
import breath from '@/views/setting/breath.vue'
import body from '@/views/setting/body.vue'
import {useAuthStore} from "@/stores/auth.js";


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL) ,//createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: (to) => {
        const authStore = useAuthStore();
        if (authStore.isAuthenticated) {
          return { path: '/index/mainIndex' };
        } else {
          return { path: '/login' };
        }
      },
      hidden: true,
      meta: {
        requireAuth: false
      }
    },
    {
      path: '/login',
      name: '登录',
      component: login,
      hidden: true,
      meta: {
        requireAuth: false
      }
    },
    {
      path: '/index',
      name: '首页',
      component: index,
      iconCls: 'el-icon-tickets',
      children: [
        {
          path: '/index/mainIndex',
          name: '实际首页',
          component: Main,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/report/generation',
          name: '报告生成',
          component: ReportGeneration,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/report/search',
          name: '报告查询',
          component: ReportSearch,
          meta: {
            requireAuth: true
          }
        },
          //慢阻肺报告
        {
          path: '/reportCOPD/generationCOPD',
          name: '报告生成COPD',
          component: ReportGenerationCOPD,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/reportCOPD/searchCOPD',
          name: '报告查询COPD',
          component: ReportSearchCOPD,
          meta: {
            requireAuth: true
          }
        },

        {
          path: '/pay/order',
          name: '交易订单',
          component: Order,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/system/user',
          name: '用户管理',
          component: user,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/system/doctor',
          name: '医生管理',
          component: doctor,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/system/role',
          name: '角色管理',
          component: Role,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/binding',
          name: '设备绑定',
          component: Binding,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/unbind',
          name: '设备解绑',
          component: Unbind,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/audit',
          name: '申请设备绑定',
          component: AuditBinding,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/borrowAndReturn',
          name: '设备借出与归还',
          component: borrowAndReturn,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/borrowAndReturn',
          name: '设备借出与归还',
          component: borrowAndReturn,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/equipment/borrowAndReturn',
          name: '设备借出与归还',
          component: borrowAndReturn,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/system/permission',
          name: '权限管理',
          component: Permission,
          meta: {
            requireAuth: true
          }
        }, {
          path: '/pay/config',
          name: '支付配置',
          component: Config,
          meta: {
            requireAuth: true
          }
        },{
          path: '/charts/statistics',
          name: '数据可视化',
          component: statistics,
          meta: {
            requireAuth: true
          }
        }
        ,{
          path: '/setting/sound',
          name: '鼾声模型设置',
          component: sound,
          meta: {
            requireAuth: true
          }
        }
        ,{
          path: '/setting/body',
          name: '体位体动模型设置',
          component: body,
          meta: {
            requireAuth: true
          }
        }
        ,{
          path: '/setting/breath',
          name: '呼吸模型设置',
          component: breath,
          meta: {
            requireAuth: true
          }
        }
        ,{
          path: '/user/info',
          name: '呼吸模型设置',
          component: UserInfo,
          meta: {
            requireAuth: true
          }
        }
        // ,{
        //   path: '/system/sleepModelSetup',
        //   name: '睡眠模型设置',
        //   component: SleepModelSetup,
        //   meta: {
        //     requireAuth: true
        //   }
        // }
      ]
    }]
})
router.beforeEach((to, from, next) => {
  const authStore = useAuthStore();
  if (to.name !== '登录' && !authStore.isAuthenticated) {
    next({ name: '登录' });
  } else {
    next();
  }
});
export default router
